//
#import "BKValue.h"

@implementation BKValue

- (id) initWithXMLElement: (NSXMLElement*) elem signatures: (BKSignatures*) sigs
{
	if(self = [super initWithXMLElement: elem signatures: sigs])
	{
		NSXMLNode* theNode;
		if(theNode = [elem attributeForName: @"c_array_length_in_arg"])
			_cArrayLengthInArg = [[theNode stringValue] integerValue];
		else
			_cArrayLengthInArg = -1;
		
		if(theNode = [elem attributeForName: @"c_array_of_fixed_length"])
			_cArrayOfFixedLength = [[theNode stringValue] integerValue];
		else
			_cArrayOfFixedLength = -1;
		
		if(theNode = [elem attributeForName: @"c_array_delimited_by_null"])
			_cArrayDelimitedByNull = [[theNode stringValue] boolValue];
		
		if(theNode = [elem attributeForName: @"c_array_of_variable_length"])
			_cArrayOfVariableLength = [[theNode stringValue] boolValue];
		
		if(theNode = [elem attributeForName: @"function_pointer"])
			_functionPointer = [[theNode stringValue] boolValue];
	}
	return self;
}

@end


@implementation BKReturnValue

+ (id) voidReturnValueWithSignatures: (BKSignatures*) sigs
{
	BKReturnValue* retVal = [[[BKReturnValue alloc] init] autorelease];
	retVal.name = @"retval";
	retVal.signatures = sigs;
	retVal.typeString = @"v";
	retVal->_cArrayLengthInArg = -1;
	retVal->_cArrayOfFixedLength = -1;
	return retVal;
}

- (id) initWithXMLElement: (NSXMLElement*) elem signatures: (BKSignatures*) sigs
{
	if(self = [super initWithXMLElement: elem signatures: sigs])
	{
		NSXMLNode* theNode;
		if(theNode = [elem attributeForName: @"already_retained"])
			_alreadyRetained = [[theNode stringValue] boolValue];
	}
	return self;
}

@end


@implementation BKArgument

- (id) initWithXMLElement: (NSXMLElement*) elem signatures: (BKSignatures*) sigs
{
	if(self = [super initWithXMLElement: elem signatures: sigs])
	{
		NSXMLNode* theNode;
		if(theNode = [elem attributeForName: @"index"])
			_index = [[theNode stringValue] integerValue];
		else
			_index = -1;
		
		if(theNode = [elem attributeForName: @"type_modifier"])
			_typeModifier = [[theNode stringValue] copy];
		
		if(theNode = [elem attributeForName: @"null_accepted"])
			_nullAccepted = [[theNode stringValue] boolValue];
		
		if(theNode = [elem attributeForName: @"printf_format"])
			_printfFormat = [[theNode stringValue] boolValue];
		
		theNode = nil;
#if __LP64__
		theNode = [elem attributeForName: @"sel_of_type64"];
#endif
		if(theNode == nil)
			theNode = [elem attributeForName: @"sel_of_type"];
		if(theNode)
			_selOfType = [[theNode stringValue] copy];
	}
	return self;
}

- (void) dealloc
{
	[_typeModifier release];
	[_selOfType release];
	[super dealloc];
}

@synthesize index = _index;

@end
